<template>
	<view>
		<wd-navbar title="数据字典" bordered placeholder safeAreaInsetTop right-text="添加" left-arrow
			@click-left="clickHeaderLeft" @click-right="clickHeaderRight">
		</wd-navbar>
		
		<view class="dictionary-list">
			<view class="dictionary-list-li" v-for="(d,index) in Data.list" clickable @click="clickDic(d,index)">
				<wd-cell border :title="d.title" :label="d.name" title-width="200px" :value="d.count + '个词条'" />
			</view>
		</view>
		
	</view>
</template>

<script setup>
	import overallRequest from "@/utool/http/http.js"
	import {
		ref,
		reactive
	} from 'vue'

	import {
		onLaunch,
		onReady
	} from '@dcloudio/uni-app'
	
	const api = ref("/dictionary/dictionaryList")
	
	let Data = reactive({
		list:[]
	})
	
	onReady(()=>{
		getDictionaryList()
	})
	// 点击字典列表
	function clickDic(item,index){
		let {id,title} = item 
		console.log(id,title);
		uni.navigateTo({
			url:`/pages/Mange/System/dictionary/dictionary_info?id=${id}&title=${title}`,
		})
	}
	// 获取字典列表
	function getDictionaryList(){
		overallRequest(api.value).then(res=>{
			let {data} = res 
			let {list} = data 
			Data.list.push(...list) 
		}).catch(err=>{
			console.log(err);
		})
	}
	// 点击返回
	function clickHeaderLeft(){
		uni.navigateBack({})
	}
	// 点击添加字典
	function clickHeaderRight(){
		uni.navigateTo({
			url:"/pages/Mange/System/dictionary/dictionary_add"
		})
	}
</script>

<style scoped>
	
	.dictionary-list{
		background: #c3c3c344;
		padding: 30rpx 20px;
	}
	
	.dictionary-list-li {
		border-bottom: 1rpx solid #c3c3c344;
		margin-bottom: 25rpx;
		padding:0rpx 10rpx;
		box-sizing: border-box;
		background: white;
		border-radius: 10px;
	}
</style>